#pragma once
#include <map>
using namespace std;

class ClientsManager;
class SkypeAPICtrl {
public:
	SkypeAPICtrl(ClientsManager* clientMan);
	~SkypeAPICtrl(void);

	void scanCtrlWin();
	void test();
	bool isReady() const {
		return m_isReady;
	}

	static SkypeAPICtrl* instanceOfWin(void* win) {
		return m_winInstMap[win];
	}
	long SkypeAPIWindowProc(void * hWindow, unsigned int uiMessage,
			unsigned int uiParam, unsigned int ulParam);
	void StartMessageLoop();
	LRESULT sendMessage(HWND targetWin, const string& msg);

private:
	bool Initialize_CreateWindowClass();
	void DeInitialize_DestroyWindowClass();
	bool Initialize_CreateMainWindow();
	void DeInitialize_DestroyMainWindow();
	void Global_InputProcessingThread();

	enum {
		SKYPECONTROLAPI_ATTACH_SUCCESS = 0, // Client is successfully attached and API window handle can be found in wParam parameter
		SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION = 1, // Skype has acknowledged connection request and is waiting for confirmation from the user.
		// The client is not yet attached and should wait for SKYPECONTROLAPI_ATTACH_SUCCESS message
		SKYPECONTROLAPI_ATTACH_REFUSED = 2, // User has explicitly denied access to client
		SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE = 3, // API is not available at the moment. For example, this happens when no user is currently logged in.
		// Client should wait for SKYPECONTROLAPI_ATTACH_API_AVAILABLE broadcast before making any further
		// connection attempts.
		SKYPECONTROLAPI_ATTACH_API_AVAILABLE = 0x8001
	};

	ClientsManager* m_clientMan;

	HWND m_hInitMainWindowHandle;
	HANDLE m_hInitProcessHandle;
	TCHAR m_initWindowClassName[128];
	unsigned long m_threadShutdownEvent;
	bool volatile m_threadRunning;
	unsigned int m_uiMsgIDSkypeControlAPIAttach;
	unsigned int m_uiMsgIDSkypeControlAPIDiscover;
	static map<void*, SkypeAPICtrl*> m_winInstMap;

	bool m_isReady;
	HANDLE m_threadHandle;

	CRITICAL_SECTION m_sendMessageCriticalSection;

};
